
const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
const ArrayMax = (arr, type) => {
  var min;
  for (var i = 0; i < arr.length; i++) {
    for (var j = i; j < arr.length; j++) {
      if (Number(arr[i][type]) < Number(arr[j][type])) {
        min = arr[j];
        arr[j] = arr[i];
        arr[i] = min;
      }
    }
  }
  return arr
}
module.exports = {
  formatTime: formatTime,
  getDateListI: getDateListI,
  ArrayMax: ArrayMax
}

function getDateListI(arr) {
  let index = 0
  let arr2 = []
  let arr3 = []
  arr.map(item => {
    let a = item.date.split('-')
    item.date = a[0] + '-' + a[1]
    arr3.push(item.date)
  })
  let a = unique(arr3)
  function unique(arr) {
    return Array.from(new Set(arr))
  }
  return function dete() {
    arr2[index] = { list: [], title: a[index] }
    arr.map(item => {
      let a = item.date.split('-')
      let b = a[0] + '-' + a[1]
      if (b == arr2[index].title) {
        arr2[index].list.push(item)
      }
    })
    if (index < a.length - 1) {
      index++
      return dete()
    } else {
      console.log(arr2)
      return arr2
    }
  }

}
